/*
 *  $Id: SetRemotePlayer.cs 1240 2011-03-23 12:57:56Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2010 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using Nereal.Serialization;

namespace Ragima.Events {
    [TypeId("setremoteplayer")]
    public class SetRemotePlayer : DirectConnectEvent {
        [Serialize, XmlName("player")]
        private readonly PlayerInfo _info;

        public SetRemotePlayer() {
            _info = new PlayerInfo("player.remote");
        }

        public SetRemotePlayer(PlayerInfo info) {
            _info = new PlayerInfo("player.remote");
            _info.Name.CopyFrom(info.Name);
            _info.AvatarFileName = info.AvatarFileName;
        }

        protected override void ExecuteInner(DirectConnectScene scene) {
            scene.Mode.SetRemotePlayer(_info);
            if (scene.Mode.Master) {
                scene.Log.Add(Resources.DirectConnect.OpponentName, _info);
                scene.EnableAcceptButtons(true);
            } else {
                scene.Log.Add(Resources.DirectConnect.OpponentWaitAccept, _info);
            }
        }
    }
}
